#include <iostream>
#include <math.h>
#include <stdlib.h>
#include <stack>

using namespace std;

int compareFunc(const void *a, const void *b)
{
	return *((int*)b) - *((int*)a);
}


bool dfs(int start, int second, int i, int n, int* sticks, bool* visited)
{
	while ((sticks[start] == i || visited[start]) && start < n) {
		++start;
		second = start + 1;
	}
	if (start >= n)
		return true;
	int pre = -1;
	for (int j = second; j < n; j++) {
		if (!visited[j] && (sticks[start] + sticks[j]) <= i && sticks[j] != pre) {
			pre = sticks[j];
			sticks[start] += sticks[j];
			visited[j] = true;
			if (dfs(start, j, i, n, sticks, visited))
				return true;
			sticks[start] -= sticks[j];
			visited[j] = false;			
		}
	}
	return false;
	///*if (totalSum == 0)
	//	return true;
	//int pre = -1;
	//for (int j = start; j < n; j++) {
	//	if (!visited[j] && sticks[j] != pre) {
	//		subSum += sticks[j];
	//		if (subSum == i){
	//			totalSum -= i;
	//			subSum = 0;				
	//			visited[j] = true;
	//			if (dfs(0, subSum, totalSum, i, n, sticks, visited)) {
	//				return true;
	//			} else {
	//				subSum = i -  sticks[j];
	//				totalSum += i;
	//				visited[j] = false;
	//			}
	//		} else if (subSum < i) {
	//			visited[j] = true;
	//			if (dfs(j + 1, subSum, totalSum, i, n, sticks, visited)) {
	//				return true;
	//			} else {
	//				subSum -= sticks[j];
	//				visited[j] = false;
	//			}
	//		} else {
	//			pre = sticks[j];
	//			subSum -= sticks[j];
	//		}
	//	}
	//}*/
	//return false;
}

int main(int argc, char* argv[])
{
	int n;
	cin>>n;
	while (n != 0) {
		int *sticks = new int[n];
		int *restore = new int[n];
		bool *visited = new bool[n];
		memset(visited, false, sizeof(bool) * n);

		int sum = 0;
		int i = 0;
		int maxLength = 0;
		for (i = 0; i < n; ++i) {
			int stickLength;
			cin>>stickLength;
			sticks[i] = stickLength;
			sum += stickLength;

			if (stickLength > maxLength)
				maxLength = stickLength;
		}
		qsort(sticks, n, sizeof(int), compareFunc);
		memcpy(restore, sticks,  n * sizeof(int));

		for (i = maxLength; i <= sum / 2; ++i)
		{
			if (sum % i == 0) {// i is a factor of sum
				memset(visited, false, sizeof(bool) * n);
				memcpy(sticks, restore, n * sizeof(int) );
				if (dfs(0, 1, i, n, sticks, visited)) {
					cout<<i<<endl;
					break;
				}
			}
		}
		if (i > sum / 2)
			cout<<sum<<endl;

		delete[] sticks;
		delete[] visited;
		delete[] restore;
		cin>>n;
	}

	return 0;
}